import request from '@/utils/request'
import { MenuParams, PermissionResponseData } from './type'

enum API {
  // 获取全部菜单与按钮标识的接口地址
  ALL_PERMISSION_URL = '/admin/acl/permission',
  // 添加菜单子菜单的接口地址
  ADD_MENU_URL = '/admin/acl/permission/save',
  // 修改菜单的接口地址
  UPDATE_URL = '/admin/acl/permission/update',
  // 递归删除菜单的接口地址
  DELETE_URL = '/admin/acl/permission/remove/',
}

// 获取全部菜单与按钮标识的接口方法
export const reqAllPermission = () =>
  request.get<any, PermissionResponseData>(API.ALL_PERMISSION_URL)
// 添加/修改菜单的接口方法
export const reqAddOrUpdateMenu = (data: MenuParams) =>
  // 根据是否有id判断添加还是修改
  data.id
    ? request.put<any, any>(API.UPDATE_URL, data)
    : request.post<any, any>(API.ADD_MENU_URL, data)
// 递归删除菜单的接口方法
export const reqRemoveMenu = (id: number) =>
  request.delete<any, any>(API.DELETE_URL + id)
